/**
 * 
 */
package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JPanel;

import model.GameDriver;

import common.GridCoordinate;

import controller.Controller;

/**
 * @author Bill Heys - 201031705
 *
 *This is the main Jpanel for the gameplay states.
 */
public class GamePanel extends JPanel{
	
	private GameDriver gameDriver;
	private MapPanel mapPanel;
	private InventoryPanel inventoryPanel;
	private JPanel messagePanel = new JPanel(new BorderLayout());
	
	private boolean inventoryItemSelected = false;
	private String selectedInventoryItemName = "";
	
	private static final long serialVersionUID = 1L;

	/**
	 * Constructs a basic blank GamePanel with an inventory panel and a map panel.
	 */
	public GamePanel(ArrayList<GridCoordinate> trailList, GameDriver driver){
		
		this.setBackground(Color.BLACK);
		this.gameDriver = driver;
		this.inventoryPanel = new InventoryPanel();
		this.mapPanel = new MapPanel(trailList, driver.getCurrentLevel());
		
		this.add(mapPanel);
		this.add(inventoryPanel);
		this.setPreferredSize(this.getPreferredSize());
		
		inventoryPanel.setLocation(mapPanel.getWidth(), 0);
		
	}
	
	/**
	 * Updates all of the game panel's child panels with data from the model
	 */
	public void updateChildren(GameDriver gameDriver){
		//update all of the components in the frame 
		inventoryPanel.updateStore(gameDriver);
		inventoryPanel.updateCargo(gameDriver);
		mapPanel.nonTickUpdate(gameDriver);
	}
	
	/**
	 * Switches the inventory panel to the store view and syncs it with the game driver data
	 * 
	 * @param gameDriver
	 */
	public void beginSetup(GameDriver gameDriver){
		this.inventoryPanel.setStorePanelFront();
		this.inventoryPanel.updateStore(gameDriver);
		Controller.stopTimer();
	}
	
	/**
	 * Switches the inventory panel to the cargo view and syncs it with the game driver data
	 * 
	 * @param gameDriver
	 */
	public void beginAttack(GameDriver gameDriver){
		this.inventoryPanel.setCargoPanelFront();
		this.inventoryPanel.updateCargo(gameDriver);
		Controller.startTimer();
	}
	
	/********************
	 * Getters and Setters
	 ********************/
	public GameDriver getGameDriver() {
		return gameDriver;
	}
	public void setGameDriver(GameDriver gameDriver) {
		this.gameDriver = gameDriver;
	}
	public MapPanel getMapPanel() {
		return mapPanel;
	}
	public void setMapPanel(MapPanel mapPanel) {
		this.remove(this.mapPanel);
		this.remove(this.inventoryPanel);
		this.mapPanel = mapPanel;
		this.add(this.mapPanel);
		this.add(this.inventoryPanel);
		this.repaint();
	}
	public InventoryPanel getInventoryPanel() {
		return inventoryPanel;
	}
	public void setInventoryPanel(InventoryPanel inventoryPanel) {
		this.inventoryPanel = inventoryPanel;
	}

	public String getSelectedInventoryItemName() {
		return selectedInventoryItemName;
	}

	public boolean isInventoryItemSelected() {
		return inventoryItemSelected;
	}
	
	
}
